package cn.com.czpb.client.module.news.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import cn.com.czpb.client.R;
import cn.com.czpb.client.api.InterfaceJsonfile;
import cn.com.czpb.client.app.MToolBarActivity;
import cn.com.czpb.client.model.news.FuWuMainBean;
import cn.com.czpb.client.model.news.FuWuMainEntity;
import cn.com.czpb.client.module.news.adapter.FuwuMainAdapter;
import cn.com.czpb.client.net.Factory;
import cn.com.czpb.client.utils.ActionbarUtils;
import cn.com.czpb.client.utils.LogUtils;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/2/24.
 */

public class FuWuMainActivity extends MToolBarActivity {
    @BindView(R.id.fuwu_recyclev)
    RecyclerView fuwurecycleview;
    private FuwuMainAdapter adapter;
    private List<FuWuMainBean> list;
    @BindView(R.id.ll_back)
    LinearLayout ll_back;
    @Override
    protected int setLayoutId() {
            return R.layout.activity_fuwu_main;
    }

    @Override
    public void initView() {

        super.initView();
        ll_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
        ActionbarUtils.setMeizuStatusBarDarkIcon(activity, true);
        ActionbarUtils.setMiuiStatusBarDarkMode(activity, true);
        final LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        fuwurecycleview.setLayoutManager(layoutManager);
        list = new ArrayList<>();
        adapter = new FuwuMainAdapter(list,FuWuMainActivity.this);
        fuwurecycleview.setAdapter(adapter);

    }

    private void getFuWuList() {
        Map<String, String> map = new HashMap();
        if(spu.getCurrentCityId() != null) {
            map.put("id", spu.getCurrentCityId());
        }else{
            map.put("id","1");
        }
        map.put("siteid", InterfaceJsonfile.SITEID);
        Factory.provideHttpService().areamainFuWuList(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<FuWuMainEntity>() {
                    @Override
                    public void call(FuWuMainEntity entity) {
                        LogUtils.i("notLike-->" + entity.code);
//                        adapter = new FuwuMainAdapter(entity.data,FuWuMainActivity.this);
//                        fuwurecycleview.setAdapter(adapter);
                        list.addAll(entity.data);
                        adapter.notifyDataSetChanged();
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LogUtils.i("异常-->" + throwable.toString());
                    }
                });
    }



    @Override
    public void initData() {
        super.initData();
        getFuWuList();
    }
}
